#include("/common/_layout.html")
#@layout()
#define layoutHead()
	<title>学生编辑</title>
#end
#define layoutBody()
	<body>
		<div class="page-content-wrap">
				<form class="layui-form" lay-filter="formedit">
					<input type="hidden" name="student_id">
					<div class="layui-tab" style="margin: 0;">
						<ul class="layui-tab-title">
							<li><a id="a_goback_url" href="javascript:window.history.back();">学生列表</a></li>
							<li class="layui-this">学生编辑</li>
						</ul>
						<div class="layui-tab-content">
							<div class="layui-tab-item"></div>
							<div class="layui-tab-item layui-show">
								<div class="layui-form-item">
									<label class="layui-form-label">学生姓名：</label>
									<div class="layui-input-block">
										<input type="text" name="student_name" required lay-verify="required" placeholder="请输入学生姓名" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">生日：</label>
									<div class="layui-input-block">
										<input type="text" name="student_birthday" required lay-verify="required" placeholder="请输入生日" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD'})">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">性别：</label>
									<div class="layui-input-block">
										<input type="radio" name="sex_id" value="1" title="男" checked>
										<input type="radio" name="sex_id" value="2" title="女">
										<input type="radio" name="sex_id" value="0" title="保密">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">学号：</label>
									<div class="layui-input-block">
										<input type="text" name="student_sno" placeholder="请输入学生学号" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">联系电话：</label>
									<div class="layui-input-block">
										<input type="text" name="student_mobile" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">学生头像：</label>
									<div class="layui-input-block">
										<input type="hidden" id="student_headpic" name="student_headpic">
										<input type="file" name="file_student_headpic" lay-ext="jpeg|jpg|png|gif" lay-type="images" lay-title="上传图片" class="layui-upload-file">
										<div id="div_student_headpic" style="padding: 5px;"></div>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">住址：</label>
									<div class="layui-input-block">
										<input type="text" name="home_address" placeholder="请输入学生住址" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">班级：</label>
									<div class="layui-input-block">
										<select id="class_id" name="class_id" lay-verify="required">
											<option value="">请选择</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">状态：</label>
									<div class="layui-input-block">
										<select name="student_stateid" lay-verify="required">
											<option value="1">启用</option>
											<option value="0">禁用</option>
										</select>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item" style="padding-left: 10px;">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
						</div>
					</div>
				</form>
		</div>
		<script src="/static/js/jquery.formHelp.js" type="text/javascript" charset="utf-8"></script>
		<script>
			
			layui.use(['form', 'layer', 'laytpl', 'element', 'upload', 'laydate'], function() {
				var form = layui.form();
				var layer = layui.layer;
				var laytpl = layui.laytpl,
					element = layui.element(),
					laydate = layui.laydate;
				
				layui.upload({
					url: '/api/eduorg/file/upload',
					success: function(res) {
						if (res.code == 0){
							var sourceId = res.data.paramid.replace("file_","");
							var ftype = $('input[name="' + res.data.paramid+'"]').attr("lay-type");
							
							$('#'+sourceId).val(res.data.src);
							
							formatUpFile(sourceId, res.data.src, ftype);
						}else{
							parent.alertMsg(res.msg);
						}
					}
				});
				
				function formatUpFile(elid, surl, ftype){
					if (surl == null || surl == "" || surl == "undefined"){
						return;
					}
					var shtml = "";
					if (ftype=="images"){
						shtml = '<img src="'+surl+'" width="100" height="100">';
					}else{
						shtml = '<a href="'+surl+'" target="_blank">'+surl.substr(surl.lastIndexOf('/')+1)+'</a>';
					}
					$('#div_'+elid).html(shtml);
				}
				
				// 表单验证
				form.verify({
				});

				//监听提交
				form.on('submit(formDemo)', function(formData){
					sendPost("/api/eduorg/student/save", formData.field, function(res) {
						layer.alert(res.msg, {
							title: '信息提示'
						}, function(idx){
							if (res.code==200){
								window.history.back();;
							}
							layer.close(idx);
						});
					});
					return false;
				});

				// 页面初始化
				function page_init(){
					var id = getUrlParam('id');

					// 加载初始化编辑数据
					sendGet("/api/eduorg/student/getOne", {
						id : getUrlParam("id")
					}, function(res) {
						//console.log(res);
						if (res.hasOwnProperty("listclass")) {
							bindSelectJSONProps("class_id", res, "listclass", "class_name", "class_id", 1);
						}
						// 初始化编辑数据
						if (res.hasOwnProperty("oneinfo")) {
							$("form.layui-form").setForm(res.oneinfo);
							formatUpFile("student_headpic", res.oneinfo.student_headpic, "images");
						}
						form.render();
					});
				}
				page_init();
			});
			
			
					
		</script>
	</body>

#end